﻿#ifndef MAINSCENE_H
#define MAINSCENE_H

#include <QGraphicsRectItem>
#include <QGraphicsScene>

enum CANVAS_OPERATION
{
    CANVAS_OPERATION_CHOOSE,
    CANVAS_OPERATION_PEN,
    CANVAS_OPERATION_PENCIL,
    CANVAS_OPERATION_LINE,
    CANVAS_OPERATION_SQUARE,
    CANVAS_OPERATION_ELLIPSE,
    CANVAS_OPERATION_TRAINGLE,
};

//QGraphicsScene管理QGraphicsItem（单击/选择/移动/缩放/删除）
// 自定义 Item
class CanvasRect : public QGraphicsRectItem
{
public:
    explicit CanvasRect(QGraphicsItem *parent = 0);
protected:
    // Shift+左键：进行选择  Alt：准备缩放
    void mousePressEvent(QGraphicsSceneMouseEvent *event);
    // Alt+拖拽：进行缩放  移动
    void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
    // 使item可使用qgraphicsitem_cast
    int type() const;
private:
    QPointF m_centerPointF;
    bool m_bResizing;
};


class CanvasEllipse : public QGraphicsEllipseItem
{
public:
    explicit CanvasEllipse(QGraphicsItem *parent = 0);
protected:
    // Shift+左键：进行选择  Alt：准备缩放
    void mousePressEvent(QGraphicsSceneMouseEvent *event);
    // Alt+拖拽：进行缩放  移动
    void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
    // 使item可使用qgraphicsitem_cast
    int type() const;
private:
    QPointF m_centerPointF;
    bool m_bResizing;
};

// 自定义 Scene
class MainScene : public QGraphicsScene
{
protected:
    // 左键：添加item  右键：移除item
    void mousePressEvent(QGraphicsSceneMouseEvent *event);
    void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
    // Backspace键移除item
    void keyPressEvent(QKeyEvent *event);
};

#endif // MAINSCENE_H
